<template>
    <view class="content">
        <view class="bg"></view>
        <view class="wrapper">
            <view class="box">
                <view class="item">
                    <view class="grey">头像</view>
                    <view class="img-box" @click="chooseAvatar">
                        <image v-if="img" :src="img" class="avatar"></image>
                        <image v-if="!img" :src="IMAGEURL + '/static/icon/avatar.png'" class="avatar"></image>
                        <view class="up">上传头像</view>    
                    </view>
                </view>
                <view class="item">
                    <view class="grey">姓名</view>
                    <view class="item-right">
                        <input type="text" v-model="name" placeholder="请输入姓名" class="inp" >
                    </view>
                </view>
                
                <view class="item">
                    <view class="grey">性别</view>
                    <view class="item-right">
                        <view class="u-flex u-p-r-50" @click.stop="chooseSex(1)">
                            <image v-if="isMale == 1" :src="IMAGEURL + 'static/icon/choose_01.png'" class="choose-01"></image>
                            <image v-else :src="IMAGEURL + 'static/icon/choose_02.png'" class="choose-01"></image>
                            <view>男</view>
                        </view>
                        <view class="u-flex" @click.stop="chooseSex(2)">
                            <image v-if="isMale == 2" :src="IMAGEURL + 'static/icon/choose_01.png'" class="choose-01"></image>
                            <image v-else :src="IMAGEURL + 'static/icon/choose_02.png'" class="choose-01"></image>
                            <view>女</view>
                        </view>
                    </view>
                </view>
                
                <view class="item">
                    <view class="grey">年龄</view>
                    <view class="item-right">
                        <input type="number" v-model="age" placeholder="请输入年龄" class="inp" >
                    </view>
                </view>
                <view class="item" @click="show_5 = true">
                    <view class="grey">出生年月日</view>
                    <view class="item-right">
                        <input type="text" v-model="birthday" placeholder="请选择" class="inp" disabled>
                        <u-icon name="arrow-down-fill" color="#535353" size="24" class="u-m-l-10"></u-icon>
                    </view>
                </view>
                
                <view class="item">
                    <view class="grey">手机号</view>
                    <view class="item-right">
                        <input type="number" v-model="tel" placeholder="请输入手机号" class="inp" disabled>
                    </view>
                </view>
                <view class="item" @click="show_2 = true">
                    <view class="grey">学历</view>
                    <view class="item-right">
                        <input type="text" v-model="education" placeholder="请选择" class="inp" disabled>
                        <u-icon name="arrow-down-fill" color="#535353" size="24" class="u-m-l-10"></u-icon>
                    </view>
                </view>
                
                <view class="item">
                    <view class="grey">就读院校</view>
                    <view class="item-right">
                        <input type="text" v-model="school" placeholder="请输入毕业院校" class="inp" >
                    </view>
                </view>
                <view class="item">
                    <view class="grey">专业</view>
                    <view class="item-right">
                        <input type="text" v-model="speciality" placeholder="请输入专业" class="inp" >
                    </view>
                </view>
                <view class="item" @click="show_6 = true">
                    <view class="grey">英语等级</view>
                    <view class="item-right">
                        <input type="text" v-model="english" placeholder="请选择" class="inp" disabled>
                        <u-icon name="arrow-down-fill" color="#535353" size="24" class="u-m-l-10"></u-icon>
                    </view>
                </view>
                <!-- <view class="item">
                    <view class="grey">家庭人口数</view>
                    <view class="item-right">
                        <input type="number" v-model="people_num" placeholder="请输入家庭人口数" class="inp">
                    </view>
                </view> -->
                
                <view class="item">
                    <view class="grey">现居省市区</view>
                    <view class="select">
                        <pick-regions @getRegion="handleGetRegion">
                            <view class="adr-box">
                                <view v-if="region">{{ region }}</view>
                                <view v-else class="place">
                                    请选择省市区<u-icon name="arrow-down-fill" color="#535353" size="24" class="u-m-l-10"></u-icon>
                                </view>
                            </view>
                        </pick-regions>
                    </view>
                </view>
                <view class="item">
                    <view class="grey">现居地址</view>
                    <view class="item-right u-flex-1">
                        <textarea v-model="current_address" maxlength="200" :auto-height="true" placeholder="请输入现居详细地址" class="t-inp2"></textarea>
                    </view>
                </view>
                
                <view class="item">
                    <view class="grey">身高</view>
                    <view class="item-right">
                        <input type="digit" v-model="height" placeholder="请输入身高" class="inp u-p-r-10" >cm
                    </view>
                </view>
                <view class="item">
                    <view class="grey">体重</view>
                    <view class="item-right">
                        <input type="digit" v-model="weight" placeholder="请输入体重" class="inp u-p-r-10" >kg
                    </view>
                </view>
                <view class="item" @click="show_7 = true">
                    <view class="grey">星座</view>
                    <view class="item-right">
                        <input type="text" v-model="star_sign" placeholder="请选择" class="inp" disabled>
                        <u-icon name="arrow-down-fill" color="#535353" size="24" class="u-m-l-10"></u-icon>
                    </view>
                </view>
                <view class="item" @click="show_1 = true">
                    <view class="grey">婚姻状况</view>
                    <view class="item-right">
                        <input type="text" v-model="marriage" placeholder="请选择" class="inp" disabled>
                        <u-icon name="arrow-down-fill" color="#535353" size="24" class="u-m-l-10"></u-icon>
                    </view>
                </view>
                <view class="item" @click="show_3 = true">
                    <view class="grey">宗教信仰</view>
                    <view class="item-right">
                        <input type="text" v-model="belief" placeholder="请选择" class="inp" disabled>
                        <u-icon name="arrow-down-fill" color="#535353" size="24" class="u-m-l-10"></u-icon>
                    </view>
                </view>
                <view class="item" @click="show_4 = true">
                    <view class="grey">政治面貌</view>
                    <view class="item-right">
                        <input type="text" v-model="politics" placeholder="请选择" class="inp" disabled>
                        <u-icon name="arrow-down-fill" color="#535353" size="24" class="u-m-l-10"></u-icon>
                    </view>
                </view>
            </view>
            
            <view class="box">
                <view class="item">
                    <view class="grey">工作经历</view>
                    <view class="item-right">
                        <view class="u-flex u-p-r-50" @click.stop="chooseWork(1)">
                            <image v-if="isWork == 1" :src="IMAGEURL + 'static/icon/choose_01.png'" class="choose-01"></image>
                            <image v-else :src="IMAGEURL + 'static/icon/choose_02.png'" class="choose-01"></image>
                            <view>有</view>
                        </view>
                        <view class="u-flex" @click.stop="chooseWork(2)">
                            <image v-if="isWork == 2" :src="IMAGEURL + 'static/icon/choose_01.png'" class="choose-01"></image>
                            <image v-else :src="IMAGEURL + 'static/icon/choose_02.png'" class="choose-01"></image>
                            <view>无</view>
                        </view>
                    </view>
                </view>
            </view>
            
            <template v-if="isWork == 1">
                <view v-for="(item, index) in workList" :key="index">
                    <view class="box">
                        <view class="work-title">工作经历{{index + 1}}</view>
                        <view class="item" @click="openWorkTime(item)">
                            <view class="grey">工作时间</view>
                            <view class="item-right u-flex-1">
                                <input type="text" v-model="item.work_date" placeholder="请选择" class="inp" disabled>
                                <image src="../../static/icon/time_02.png" class="time-02"></image>
                            </view>
                        </view>
                        <view class="item">
                            <view class="grey">工作单位</view>
                            <view class="item-right u-flex-1">
                                <input type="text" v-model="item.work_unit" placeholder="请输入工作单位" class="inp u-p-r-10" >
                            </view>
                        </view>
                        <view class="item">
                            <view class="grey">单位详细地址</view>
                            <view class="item-right u-flex-1">
                                <textarea v-model="item.work_address" maxlength="200" :auto-height="true" placeholder="请输入单位详细地址" class="t-inp2"></textarea>
                            </view>
                        </view>
                        <view class="item" @click="openDepartTime(item)">
                            <view class="grey">离职时间</view>
                            <view class="item-right">
                                <input type="text" v-model="item.depart_date" placeholder="请选择" class="inp" disabled>
                                <image src="../../static/icon/time_02.png" class="time-02"></image>
                            </view>
                        </view>
                        <view class="item">
                            <view class="grey">领导名称</view>
                            <view class="item-right">
                                <input type="text" v-model="item.leader" placeholder="请输入领导名称" class="inp u-p-r-10" >
                            </view>
                        </view>
                        <view class="item">
                            <view class="grey">领导电话</view>
                            <view class="item-right">
                                <input type="number" v-model="item.leader_phone" placeholder="请输入领导电话" class="inp u-p-r-10" >
                            </view>
                        </view>
                    </view>
                    <view class="btns">
                        <image src="../../static/icon/add_02.png" class="add-02" @click="addWork"></image>
                        <image src="../../static/icon/del_02.png" class="del-02" v-if="workList.length > 1" @click="delWork(index)"></image>
                    </view>
                </view>
            </template>
            
            <view class="box">
                <view class="item">
                    <view class="grey">紧急联系人</view>
                    <view class="item-right">
                        <input type="text" v-model="contacts" placeholder="请输入紧急联系人" class="inp" >
                    </view>
                </view>
                <view class="item" @click="show_8 = true">
                    <view class="grey">与紧急联系人的关系</view>
                    <view class="item-right">
                        <input type="text" v-model="rela" placeholder="请选择" class="inp" disabled>
                        <u-icon name="arrow-down-fill" color="#535353" size="24" class="u-m-l-10"></u-icon>
                    </view>
                </view>
                <view class="item">
                    <view class="grey">紧急联系人电话</view>
                    <view class="item-right">
                        <input type="number" v-model="contacts_phone" placeholder="请输入紧急联系人电话" class="inp" >
                    </view>
                </view>
            </view>
            <view class="box">
                <view class="item2">
                    <view class="grey">上传毕业证</view>
                    <view class="img-box">
                        <image v-if="data.diploma_img" :src="data.diploma_img" class="up-icon2" @click="doPreviewExample(data.diploma_img)"></image>
                        <view class="u-rela" v-for="(item, index) in diplomaImg" :key="index">
                            <image :src="item" class="up-icon2" @click="doPreview(diplomaImg, index)"></image>
                            <view class="del-img" v-if="item" @click.stop="delImg(index, 1)">删除</view>
                        </view>
                        <image :src="IMAGEURL + 'static/image/up.png'" class="up-icon2" @click="chooseImage(1)"></image>
                    </view>
                </view>
                <view class="item2">
                    <view class="grey">学位证</view>
                    <view class="img-box">
                        <image v-if="data.degree_img" :src="data.degree_img" class="up-icon2" @click="doPreviewExample(data.degree_img)"></image>
                        <view class="u-rela" v-for="(item, index) in degreeImg" :key="index">
                            <image :src="item" class="up-icon2" @click="doPreview(degreeImg, index)"></image>
                            <view class="del-img" v-if="item" @click.stop="delImg(index, 2)">删除</view>
                        </view>
                        <image :src="IMAGEURL + 'static/image/up.png'" class="up-icon2" @click="chooseImage(2)"></image>
                    </view>
                </view>
                <view class="item2">
                    <view class="grey">资格证书</view>
                    <view class="img-box">
                        <image v-if="data.skill_img" :src="data.skill_img" class="up-icon2" @click="doPreviewExample(data.skill_img)"></image>
                        <view class="u-rela" v-for="(item, index) in skillImg" :key="index">
                            <image :src="item" class="up-icon2" @click="doPreview(skillImg, index)"></image>
                            <view class="del-img" v-if="item" @click.stop="delImg(index, 3)">删除</view>
                        </view>
                        <image :src="IMAGEURL + 'static/image/up.png'" class="up-icon2" @click="chooseImage(3)"></image>
                    </view>
                </view>
            </view>
            
            <view class="box">
                <view class="item2">
                    <view class="grey u-p-b-15">爱好及特长</view>
                    <textarea v-model="be_good_at" maxlength="41" :auto-height="true" placeholder="请输入爱好及特长" class="t-inp" @input="focus"></textarea>
                    <view class="words grey2">{{be_good_at.length}}/40字</view>
                </view>
            </view>
            
            <view class="btn" @click="doSubmit">确认提交</view>
        </view>
        
        <!-- 婚姻状况 -->
        <u-select v-model="show_1" mode="single-column" :list="data.marriage" value-name="id" label-name="name" @confirm="confirm($event, 1)"></u-select>
        <!-- 学历 -->
        <u-select v-model="show_2" mode="single-column" :list="data.education" value-name="id" label-name="name" @confirm="confirm($event, 2)"></u-select>
        <!-- 宗教信仰 -->
        <u-select v-model="show_3" mode="single-column" :list="data.belief" value-name="id" label-name="name" @confirm="confirm($event, 3)"></u-select>
        <!-- 政治面貌 -->
        <u-select v-model="show_4" mode="single-column" :list="data.politics" value-name="id" label-name="name" @confirm="confirm($event, 4)"></u-select>
        <!-- 出生年月 -->
        <u-picker v-model="show_5" mode="time" :params="timeParams" @confirm="chooseTime"></u-picker>
        <!-- 英语等级 -->
        <u-select v-model="show_6" mode="single-column" :list="data.english" value-name="id" label-name="name" @confirm="confirm($event, 6)"></u-select>
        <!-- 星座 -->
        <u-select v-model="show_7" mode="single-column" :list="data.star_sign" value-name="id" label-name="name" @confirm="confirm($event, 7)"></u-select>
        <!-- 关系 -->
        <u-select v-model="show_8" mode="single-column" :list="data.relation" value-name="id" label-name="name" @confirm="confirm($event, 8)"></u-select>
        <!-- 工作时间 范围 -->
        <!-- <u-calendar v-model="workShow" :mode="range" @change="change"></u-calendar> -->
        <u-picker v-model="workShow" mode="time" :params="timeParams" @confirm="change"></u-picker>
        <!-- 离职时间 -->
        <u-picker v-model="departShow" mode="time" :params="timeParams" @confirm="chooseDepartTime"></u-picker>
        
    </view>
</template>

<script>
    import { IMAGEURL } from '@/static/js/common.js';
    import { URL } from '@/static/js/common.js';
    import pickRegions from '@/components/pick-regions/pick-regions.vue';
    export default {
        components: {
            pickRegions
        },
        data() {
            return {
                URL: URL, //上传图片用的
                IMAGEURL,
                show_1: false,//婚姻状况
                show_2: false,//学历
                show_3: false,//宗教信仰
                show_4: false,//政治面貌
                show_5: false,//出生年月
                show_6: false,//英语等级
                show_7: false,//星座
                show_8: false,//与紧急联系人的关系
                workShow: false,//工作时间 范围
                departShow: false,//离职时间
                timeParams: { //时间格式
                	year: true,
                	month: true,
                	day: true,
                	hour: false,
                	minute: false,
                	second: false
                },
                data: {},//下拉选项
                img: '',
                imgId: '',//头像
                name: '',
                isMale: 1,//1男 2女
                age: '',
                birthday: '',
                tel: '',
                education: '',//学历
                education_id: '',
                school: '',//就读院校
                speciality: '',//专业
                english: '',//英语等级
                english_id: '',
                region: '', //现居省市区
                current_address: '',//现居详细地址
                height: '',//身高
                weight: '',//体重
                star_sign: '',//星座
                star_sign_id: '',
                marriage: '',//婚姻
                marriage_id: '',
                belief: '',//宗教信仰
                belief_id: '',
                politics: '',//政治面貌
                politics_id: '',
                isWork: 2,//1有 2无
                workList: [{work_date: '', work_unit: '', work_address: '', depart_date: '', leader: '', leader_phone: ''}],
                workItem: {},
                contacts: '',//紧急联系人
                rela: '',//与紧急联系人的关系
                relation_id: '',
                contacts_phone: '',//紧急联系人电话
                diplomaImg: [],//毕业证
                diplomaImgId: [],
                degreeImg: [],//学位证
                degreeImgId: [],
                skillImg: [],//资格证
                skillImgId: [],
                be_good_at: '',//爱好及特长
            };
        },
        onLoad() {
            var _this =this
            // uni.$on('uAvatarCropper', data => {
            //     _this.$upLoadPic(data.path).then(ret => {
            //         // console.log(ret)
            //         if (data.fromWhere == "logo"){
            //             _this.imgId = ret.detail.image_id
            //             _this.img = ret.detail.image
            //         }
            //     });
            // })
            
            uni.$on('ApplyAvatar', data => {
                _this.$upLoadPic(data).then(ret => {
                    console.log('ApplyAvatar',ret)
                    _this.imgId = ret.detail.image_id
                    _this.img = ret.detail.image
                });
            })
            
            this.getInfo()
            this.getOption()
        },
        methods: {
            chooseAvatar() {
                uni.chooseImage({
                    count: 1, // 默认9
                    sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                    sourceType: ['camera'], // 可以指定来源是相册还是相机，默认二者都有
                    success: res => {
                        let imageSrc = res.tempFilePaths[0];
                        this.$gTo(`/mine/pages/cropper/cropper?imageSrc=${imageSrc}`)
                    }
                });
            },
            
            focus() {
                let str = this.be_good_at
                if (str.length > 40) {
                    this.$toast('请您注意填写内容时文字数量要小于等于40个字')
                    // this.$nextTick(() => {
                        
                    // })
                    setTimeout(() => {
                        this.be_good_at = str.substring(0, str.length - 1);
                    }, 1500)
                }
            },
            
            // 添加工作经历
            addWork() {
                this.workList.push({work_date: '', work_unit: '', work_address: '', depart_date: '', leader: '', leader_phone: ''})
            },
            
            // 删除工作经历
            delWork(index) {
                this.workList.splice(index, 1)
            },
            
            openWorkTime(item) {
                this.workItem = item
                this.workShow = true
            },
            
            openDepartTime(item) {
                this.workItem = item
                this.departShow = true
            },
            
            // 选择工作时间
            change(e) {
                console.log(e);
                this.workItem.work_date = e.year + '-' + e.month + '-' + e.day;
            },
            
            // 选择离职时间
            chooseDepartTime(e) {
                this.workItem.depart_date = e.year + '-' + e.month + '-' + e.day;
            },
                        
            // 选择性别
            chooseSex(num) {
                this.isMale = num
            },
            
            // 选择是否有工作经历
            chooseWork(num) {
                this.isWork = num
            },
            
            //选择时间
            chooseTime(e) {
            	this.birthday = e.year + '-' + e.month + '-' + e.day;
            },
            
            // 根据生日计算年龄，通过获取当前日期与生日日期的年份差来计算年龄。如果当前月份小于生日月份，或者当前月份等于生日月份但是当前日期小于生日日期，表示还未到生日，将计算的年份减1。
            // calculateAge(birthday) {
            //     let today = new Date();
            //     let birthDate = new Date(birthday);
            //     let age = today.getFullYear() - birthDate.getFullYear();
            //     let monthDifference = today.getMonth() - birthDate.getMonth();
            //     if (monthDifference < 0 || (monthDifference === 0 && today.getDate() < birthDate.getDate())) {
            //         age--;
            //     }
            //     console.log('age',age)
            //     // this.age = age
            // },
            
            //选择地区
            handleGetRegion(region) {
                console.log(region);
                this.region = region[0].name + region[1].name + region[2].name
            },
            
            getInfo() {
            	this.$ajax('companion_detail', {
            		user_token: this.$getSync('userToken'),
            	}).then(ret => {
            		if (ret.success == 1000) {
                        this.tel = ret.detail.mobile
                        if (ret.detail.status == 3) {
                            let info = ret.detail
                            
                            this.img = info.service_img
                            this.imgId = info.service_img_id
                            this.name = info.name
                            this.isMale = info.gender
                            this.age = info.age
                            this.birthday = info.birthday
                            this.education = info.education
                            this.education_id = info.education_id
                            this.school = info.school //就读院校
                            this.speciality = info.speciality //专业
                            this.english = info.english //英语等级
                            this.english_id = info.english_id
                            this.region = info.current_province //现居省市区
                            this.current_address = info.current_address //现居详细地址
                            this.height = info.height//身高
                            this.weight = info.weight//体重
                            this.star_sign = info.star_sign//星座
                            this.star_sign_id = info.star_sign_id
                            this.marriage = info.marriage //婚姻
                            this.marriage_id = info.marriage_id
                            this.belief = info.belief //宗教
                            this.belief_id = info.belief_id
                            this.politics = info.politics //政治面貌
                            this.politics_id = info.politics_id
                            this.isWork = info.is_work//1有 2无
                            this.workList = info.work_history //工作经历
                            this.contacts = info.contacts//紧急联系人
                            this.rela = info.relation//与紧急联系人的关系
                            this.relation_id = info.relation_id
                            this.contacts_phone = info.contacts_phone//紧急联系人电话
                            this.be_good_at = info.be_good_at//爱好及特长
                            
                            //毕业证
                            if (info.diploma_images && info.diploma_images.length > 0) {
                                info.diploma_images.forEach(cur => {
                                    this.diplomaImg.push(cur.image)
                                    this.diplomaImgId.push(cur.id)
                                })
                            }
                            
                            //学位证
                            if (info.degree_images && info.degree_images.length > 0) {
                                info.degree_images.forEach(cur => {
                                    this.degreeImg.push(cur.image)
                                    this.degreeImgId.push(cur.id)
                                })
                            }
                            
                            //资格证
                            if (info.skill_images && info.skill_images.length > 0) {
                                info.skill_images.forEach(cur => {
                                    this.skillImg.push(cur.image)
                                    this.skillImgId.push(cur.id)
                                })
                            }
                        }
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
            
            doSubmit() {
                if (!this.imgId) {
                    this.$toast('请上传头像')
                    return
                }
                if (!this.name) {
                    this.$toast('请输入姓名')
                    return
                }
                if (!this.age) {
                    this.$toast('请输入年龄')
                    return
                }
                if (!this.birthday) {
                    this.$toast('请选择出生年月日')
                    return
                }
                if (!this.education_id) {
                    this.$toast('请选择学历')
                    return
                }
                if (!this.school) {
                    this.$toast('请输入就读院校')
                    return
                }
                if (!this.speciality) {
                    this.$toast('请输入专业')
                    return
                }
                if (!this.english_id) {
                    this.$toast('请选择英语等级')
                    return
                }
                if (!this.region) {
                    this.$toast('请选择现居省市区')
                    return
                }
                if (!this.current_address) {
                    this.$toast('请输入现居详细地址')
                    return
                }
                if (!this.height) {
                    this.$toast('请输入身高')
                    return
                }
                if (!this.weight) {
                    this.$toast('请输入体重')
                    return
                }
                if (!this.star_sign_id) {
                    this.$toast('请选择星座')
                    return
                }
                if (!this.marriage_id) {
                    this.$toast('请选择婚姻状况')
                    return
                }
                if (!this.belief_id) {
                    this.$toast('请选择宗教信仰')
                    return
                }
                if (!this.politics_id) {
                    this.$toast('请选择政治面貌')
                    return
                }
                
                let isNull = false, workArr = []
                if (this.isWork == 1) {
                    if (this.workList.length <= 0) {
                        this.$toast('请添加工作经历');
                        return false;
                    }
                    this.workList.forEach(el => {
                        if (!el.work_date || !el.work_unit || !el.work_address || !el.depart_date || !el.leader || !el.leader_phone) {
                            isNull = true;
                        }
                    });
                    if (isNull) {
                        this.$toast('请将工作经历填写完整');
                        return false;
                    } else {
                        workArr = this.workList
                    }
                } else {
                    workArr = []
                }
                
                if (!this.contacts) {
                    this.$toast('请输入紧急联系人')
                    return
                }
                if (!this.relation_id) {
                    this.$toast('请选择与紧急联系人的关系')
                    return
                }
                if (!this.contacts_phone) {
                    this.$toast('请输入紧急联系人电话')
                    return
                }
                if (!this.$checkPhone(this.contacts_phone)) {
                    this.$toast('紧急联系人电话格式不正确');
                    return false;
                }
                
                if (this.diplomaImgId.length <= 0) {
                    this.$toast('请上传毕业证')
                    return
                }
                if (this.degreeImgId.length <= 0) {
                    this.$toast('请上传学位证')
                    return
                }
                if (this.skillImgId.length <= 0) {
                    this.$toast('请上传资格证书')
                    return
                }
                if (!this.be_good_at) {
                    this.$toast('请输入爱好及特长')
                    return
                }
                
                
                this.$ajax('apply_service', {
                	user_token: this.$getSync('userToken'),
                    service_img_id: this.imgId,//头像id
                    marriage_id: this.marriage_id,//婚姻状态id
                    education_id: this.education_id,//学历id
                    // people_num: this.people_num,//家庭人口数量
                    belief_id: this.belief_id,//宗教信仰id
                    politics_id: this.politics_id,//政治面貌id
                    
                    name: this.name,//姓名
                    gender: this.isMale,//性别 1男2女
                    age: this.age,//年龄
                    birthday: this.birthday,//出生日期
                    school: this.school,//毕业学校
                    speciality: this.speciality,// 专业
                    english_id: this.english_id,//英语等级id
                    current_province: this.region,//现居地址 省市区
                    current_address: this.current_address,//现居地址
                    height: this.height,//身高
                    weight: this.weight,//体重
                    star_sign_id: this.star_sign_id,//星座id
                    contacts: this.contacts,//紧急联系人
                    relation_id: this.relation_id,//紧急联系人关系id
                    contacts_phone: this.contacts_phone,//紧急联系人电话
                    is_work: this.isWork,//工作经历 1有 2无
                    diploma_ids: this.diplomaImgId.join(','),// 毕业证id
                    degree_ids: this.degreeImgId.join(','),// 学位证id
                    skill_ids: this.skillImgId.join(','),//技能资格证id
                    be_good_at: this.be_good_at,//爱好及特长
                    data: workArr,//工作经历 数组
                }).then(ret => {
                	if (ret.success == 1000) {
                		this.$toast('提交成功')
                        setTimeout(() => {
                            this.$backT()
                        }, 500)
                	} else {
                		this.$toast(ret.msg);
                	}
                });
            },
            
            confirm(e, num) {
                console.log(e);
                if (num == 1) {
                    //婚姻状况
                    this.marriage = e[0].label
                    this.marriage_id = e[0].value
                } else if (num == 2) {
                    //学历
                    this.education = e[0].label
                    this.education_id = e[0].value
                } else if (num == 3) {
                    //宗教信仰
                    this.belief = e[0].label
                    this.belief_id = e[0].value
                } else if (num == 4) {
                    //政治面貌
                    this.politics = e[0].label
                    this.politics_id = e[0].value
                } else if (num == 6) {
                    //英语等级
                    this.english = e[0].label
                    this.english_id = e[0].value
                } else if (num == 7) {
                    //星座
                    this.star_sign = e[0].label
                    this.star_sign_id = e[0].value
                } else if (num == 8) {
                    //与紧急联系人的关系
                    this.rela = e[0].label
                    this.relation_id = e[0].value
                }
            },
            
            // 获取下拉选项
            getOption(){
            	this.$ajax('apply_service_option', {
            		
            	}).then(ret => {
            		if (ret.success == 1000) {
            			this.data = ret.detail
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
            
            chooseImage(num) {
                var _this = this;
                uni.chooseImage({
                    count: 9, //默认9
                    sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                    sourceType: ['album', 'camera'], // 相机拍照 album 相册、camera 拍照
                    success: function(res) {
                        const tempFilePaths = res.tempFilePaths;
                        for (let i = 0; i < tempFilePaths.length; i++) {
                            uni.uploadFile({
                                url: _this.URL + 'api/upload_image', //仅为示例，并非真实接口地址。
                                filePath: res.tempFilePaths[i],
                                name: 'image',
                                success: result => {
                                    let data = JSON.parse(result.data).detail; //后台返回的路径data.attach_uri
                                    
                                    if (num == 1) {
                                        //毕业证
                                        _this.diplomaImg.push(data.image);
                                        _this.diplomaImgId.push(data.image_id);
                                    } else if (num == 2) {
                                        //学位证
                                        _this.degreeImg.push(data.image);
                                        _this.degreeImgId.push(data.image_id);
                                    } else if (num == 3) {
                                        //资格证
                                        _this.skillImg.push(data.image);
                                        _this.skillImgId.push(data.image_id);
                                    }
                                }
                            });
                        }
                    }
                });
            },
            
            //预览照片
            doPreview(data, index) {
                let arr = []
                data.forEach(el => {
                    arr.push(el)
                })
                uni.previewImage({
                    urls: arr,
                    current: index,
                    longPressActions: {
                        success: function(data) {
                        },
                        fail: function(err) {
                        }
                    }
                });
            },
            
            // 预览示例
            doPreviewExample(url) {
                let arr = []
                arr.push(url)
                uni.previewImage({
                    urls: arr,
                    longPressActions: {
                        success: function(data) {
                        },
                        fail: function(err) {
                        }
                    }
                });
            },
            
            //删除照片
            delImg(index, num) {
                uni.showModal({
                    title: '提示',
                    content: '确定要删除照片吗？',
                    success: res => {
                        if (res.confirm) {
                            if (num == 1) {
                                //毕业证
                                this.diplomaImg.splice(index, 1);
                                this.diplomaImgId.splice(index, 1);
                            } else if (num == 2) {
                                //学位证
                                this.degreeImg.splice(index, 1);
                                this.degreeImgId.splice(index, 1);
                            } else if (num == 3) {
                                //资格证
                                this.skillImg.splice(index, 1);
                                this.skillImgId.splice(index, 1);
                            }
                        } else if (res.cancel) {
                            
                        }
                    }
                });
            },
        }
    };
</script>

<style lang="scss">
    .work-title{
        font-size: 32rpx;
        font-weight: bold;
        padding-top: 30rpx;
    }
    .btns{
        display: flex;
        justify-content: flex-end;
        align-items: center;
        padding-bottom: 40rpx;
    }
    .add-02{
        width: 152rpx;
        height: 56rpx;
    }
    .del-02{
        width: 57rpx;
        height: 57rpx;
        margin-left: 25rpx;
    }
    .time-02{
        width: 27rpx;
        height: 28rpx;
        margin-left: 10rpx;
        margin-bottom: 3rpx;
    }
    
    
    
    
    .choose-01{
        width: 33rpx;
        height: 33rpx;
        margin-right: 10rpx;
    }
    
    .words{
        text-align: right;
    }
    .select {
        flex: 1;
    }
    .adr-box {
        text-align: right;
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }
    .adr-box > view {
        width: 100%;
        font-size: 28upx;
        text-align: right;
    }
    .place {
        text-align: right;
        font-size: 28upx;
        color: #888888;
        margin-right: 10upx;
    }
    
    
    .t-inp{
        width: 100%;
        min-height: 100rpx;
        height: auto;
    }
    .t-inp2{
        width: 100%;
        height: auto;
        text-align: right;
    }
    
    .img-box{
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-start;
        align-items: center;
        // padding-top: 15rpx;
    }
    .up-icon2{
        width: 204rpx;
        height: 204rpx;
        margin-right: 12rpx;
        margin-top: 12rpx;
    }
    .up-icon2:nth-child(3n) {
        margin-right: 0;
    }
    .del-img{
        position: absolute;
        right: 12rpx;
        bottom: 0;
        color: #FFFFFF;
        font-size: 22rpx;
        padding: 7rpx 12rpx;
        background-color: #000000;
        opacity: .7;
        border-radius: 5rpx;
    }
    
    
    page{
        background-color: #f5f5f5;
    }
    .bg {
    	width: 100%;
    	height: 390rpx;
    	position: absolute;
    	top: 0;
    	left: 0;
    	z-index: -1;
    	background: linear-gradient(to bottom, #f29700, #f5f5f5);
    }
    .wrapper{
        padding: 20rpx;
    }
    .box{
        padding: 0 20rpx;
        background-color: #fff;
        border-radius: 15rpx;
        margin-bottom: 30rpx;
    }
    
    .item2{
        padding: 35rpx 0;
        border-bottom: 2rpx solid #eee;
    }
    .item2:last-child{
        border-bottom: none;
    }
    .item{
        padding: 35rpx 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 2rpx solid #eee;
    }
    .item:last-child{
        border-bottom: none;
    }
    .grey{
        color: #000;
    }
    .grey2{
        color: #949494;
    }
    .img-box{
        position: relative;
    }
    .avatar{
        width: 120rpx;
        height: 120rpx;
        border-radius: 50%;
    }
    .up{
        width: 100rpx;
        height: 33rpx;
        background-color: #f6f6f6;
        border-radius: 6rpx;
        font-size: 22rpx;
        color: #9a9a9a;
        text-align: center;
        line-height: 33rpx;
        position: absolute;
        bottom: -10rpx;
        left: 50%;
        transform: translateX(-50%);
    }
    .item-right{
        display: flex;
        justify-content: flex-end;
        align-items: center;
        padding-left: 15rpx;
    }
    .inp{
        flex: 1;
        text-align: right;
    }
    
    .btn{
        font-size: 34rpx;
        color: #fff;
        text-align: center;
        padding: 25rpx;
        background-color: #f29700;
        border-radius: 10rpx;
        margin: 50rpx 0;
    }

</style>
